package com.qpcy.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.qpcy.dto.CasesDto;
import com.qpcy.entity.Cases;
import com.qpcy.entity.ProductCase;
import com.qpcy.mapper.CasesMapper;
import com.qpcy.mapper.ProductCaseMapper;
import com.qpcy.service.ProductCaseService;
import com.qpcy.utils.ResponseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

import static com.qpcy.entity.table.ProductCaseTableDef.PRODUCT_CASE;

/**
 * 产品-案例映射表 服务层实现。
 *
 * @author LENOVO
 * @since 2024-10-19
 */
@Service
@Transactional
public class ProductCaseServiceImpl extends ServiceImpl<ProductCaseMapper, ProductCase> implements ProductCaseService {

    @Autowired
    private ProductCaseMapper productCaseMapper;
    @Autowired
    private CasesMapper casesMapper;

    @Override
    public ResponseResult updateProductCases(CasesDto dto) {
//        Cases cases = new Cases();
//        BeanUtils.copyProperties(dto, cases);
//        casesMapper.update(cases);
//
//        QueryWrapper queryWrapper = QueryWrapper.create()
//                .where(PRODUCT_CASE.CASE_ID.eq(dto.getCaseId()));
//        productCaseMapper.deleteByQuery(queryWrapper);
//
//        List<ProductCase> productCases = dto.getProductIds().stream()
//                .map(item -> {
//                    ProductCase productCase = new ProductCase();
//                    productCase.setCaseId(dto.getCaseId());
//                    productCase.setProductId(item);
//                    return productCase;
//                }).collect(Collectors.toList());
//
//        productCaseMapper.insertBatch(productCases);
        return ResponseResult.success();
    }
}
